import React from 'react'
import styles from './style.css'
import MyIconImage from "../MyIconImage";
import pageRedux from "../../page/pageRedux";
import MyAlert1 from "../../util/alert";
import {localClearAll} from "../../util/local";
import {clearCookie} from "../../util/cookie";

export class UserProfileAvatar extends React.Component {
    constructor(props) {
        super()
        this.state = {
            user: props.getStore("user.user") || props.user
        }
    }

    onClickName() {
        MyAlert1.confirm("确定退出？").then(res => {
            if (res.success) {
                localClearAll()
                clearCookie()
                setTimeout(() => {
                    location.href = "/login"
                }, 200)

            }
        })
    }

    render() {
        var user = this.state.user
        return <div className={styles.UserProfileAvatar}>
            <div className={styles.image}>
                <MyIconImage image={user.avatar_url}></MyIconImage>
            </div>

            <div className={styles.name} onClick={this.onClickName.bind(this)}>
                {user.name}
            </div>

        </div>
    }
}

UserProfileAvatar.defaultProps = {
    user: {
        avatar_url: ""
    }
}
export default pageRedux(UserProfileAvatar)